import { SkillCastTargetType,SkillCastType } from './SkillTypes'
export default class Skill{
  id:number = 0
  // 目标类型
  castTarget:SkillCastTargetType = SkillCastTargetType.None
  // 施法类型
  castType:SkillCastType = SkillCastType.None
  // 冷却
  coolDown:number = 0
  // 持续时间
  duration:number = 0
  spellStartEventList:Array<Function> = new Array<Function>()
  spellSuccessEventList:Array<Function> = new Array<Function>()
  spellFaildEventList:Array<Function> = new Array<Function>()
  spellCompletedtEventList:Array<Function> = new Array<Function>()
  
  constructor(id:number,castType:SkillCastType,castTarget:SkillCastTargetType,cooldown:number,duration:number){
    this.id = id
    this.castType = castType
    this.castTarget = castTarget
    this.coolDown = cooldown
    this.duration = duration
  }
  onSpellStart(callback:Function){
    this.spellStartEventList.push(callback)
  }
  spellStart(){
    const result = this.spellStartEventList.map(func=>func()).find(res=>res === false)
    return result === false
  }
  onSpellSuccess(callback:Function){
    this.spellSuccessEventList.push(callback)
  }
  
  spellSuccess(){
    this.spellSuccessEventList.map(func=>func())
  }

  onSpellFaild(callback:Function){
    this.spellFaildEventList.push(callback)
  }
  onSpellCompleted(callback:Function){
    this.spellCompletedtEventList.push(callback)
  }
}
